package com.ssm.zyn.service.impl;

import com.ssm.zyn.dao.UserMapper;
import com.ssm.zyn.eo.UserEOpage;
import com.ssm.zyn.model.User;
import com.ssm.zyn.service.Userservice;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实现业务及流程接口当中的内容
 */
@Service
public class UserServiceImpl implements Userservice {
    @Autowired
    private UserMapper userMapper;
    @Override
    public int AddUser(User user) {
        int returnInt = 0;
        /**1.业务的判断
         * (1)角色名称不能重复
         */
        //(1)判断角色
        int idCardCount = userMapper.getUserIdCardCount(user.getIdcard());
        if (idCardCount < 1) {
            //2.数据的添加
            int addUserInt = userMapper.insertUser(user);
            //3.返回值的设置
            returnInt = addUserInt;
        } else {
            returnInt = -1;//有相同的身份证号名称
        }

        return returnInt;
    }



    @Override
    public int UpdateUser(User user) {
        int isUpdate = 0;
        int uidCard=userMapper.getUserIdCardCount(user.getIdcard());
        /*1.没有相关业务流程的判断*/
        try {if (uidCard<1) {
            isUpdate = userMapper.updateUser(user);
        }
        } catch (Exception e) {
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因为"+e.getMessage());
        }
        return isUpdate;

    }

    @Override
    public int DeleteUser(int uid) {
        int delUser=0;
        /*1.有关业务流程的判断*/
        try{


                delUser=userMapper.delUser(uid);

        }catch (Exception e){
            delUser=-1;
            System.out.println("删除角色信息时执行SQL报错，信息为"+e.getMessage());
        }

        return delUser;
    }

    @Override
    public List<UserEOpage> getWhereAll(UserEOpage userEOpage) {
        List<UserEOpage> listUser=userMapper.getWhereAll(userEOpage);
        return listUser;
    }

    @Override
    public List<UserEOpage> getWhereSome( String loginname, String password) {

        List<UserEOpage> listUser1=userMapper.getWhereSome(loginname, password);
        return listUser1;
    }

}
